<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2018/7/16 0016
  Time: 上午 10:54
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>
<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"/>
    <script src="../../js/jquery-3.3.1.min.js" charset="utf-8"></script>
    <script src="../../js/cookie/jquery.cookie.js" charset="utf-8"></script>
    <script src="../../layui-v2.2.5/layui/layui.js" charset="utf-8"></script>
    <link rel="stylesheet" href="../../layui-v2.2.5/layui/css/layui.css" media="all">
    <title>开关
    </title>
</head>
<body>
<form class="layui-form" action="">
    <table class="layui-table" width="100%">

        <thead>
        <tr>

            <th width="30%">网站名称</th>
            <th width="50%">状态</th>
        </tr>
        </thead>
        <tbody>
        <c:forEach items="${data.data}" var="rl">
            <tr>
                <td><c:choose>
                    <c:when test="${rl.element=='yjfstate'}">
                        易缴费网
                    </c:when>
                    <c:when test="${rl.element=='xkstate'}">
                        闲卡网
                    </c:when>
                    <c:when test="${rl.element=='sklstate'}">
                        收卡啦网
                    </c:when>
                    <c:when test="${rl.element=='suxiaoka'}">
                        速效卡
                    </c:when>
                    <c:when test="${rl.element=='mifeng'}">
                        蜜蜂平台
                    </c:when>
                </c:choose>


                </td>


                <td>
                    <div class="layui-input-block">
                        <input type="checkbox" name="close"
                            ${rl.value==0?'checked':''} value="${rl.element}" lay-filter="switchK"
                               lay-skin="switch" lay-text="开|关"/>
                    </div>

                </td>
            </tr>
        </c:forEach>
        </tbody>
    </table>
</form>
<script>

    layui.use(['form', 'table'], function () {
        var table = layui.table;
        var form = layui.form;


        //监听指定开关
        form.on('switch(switchK)', function (data) {
            var flag = this.checked;
            var webName = data.value;

            $.ajax({
                url: '/shop/setWebOn',
                type: 'POST', //GET
                async: true,    //或false,是否异步
                data: {'element': webName, 'value': (flag ? 0 : 1)},
                timeout: 5000,    //超时时间
                dataType: 'json',    //返回的数据格式：json/xml/html/script/jsonp/text
                beforeSend: function (xhr) {
                    /*console.log(xhr)
                     console.log('发送前')*/
                },
                success: function (reData) {
                    if (reData.result) {
                        window.location.href = "/shop/modifiCation"
                    }else{
                        layui.use("layer",function(){
                            layer.msg("更改状态失败");
                        });
                    }


                },
                error: function (xhr, textStatus) {
                    console.log('错误')
                    console.log(xhr)
                    console.log(textStatus)
                },
                complete: function () {
                    //console.log('结束')
                }
            });


        });
    });

</script>


</body>
</html>